<?php
	if( !isset($_COOKIE["username"]) ){
		header("Location:login.php");
	}else{
		setcookie("username", $_COOKIE["username"], time() + 900);
	}
	
	$ini_array = parse_ini_file("config/config.ini");
	
	$conn = @mysqli_connect($ini_array["host"], $ini_array["username"], $ini_array["password"], $ini_array["db_name"]) or die("cann't connect the mysql db");
	mysqli_set_charset($conn, "utf8");
	ini_set('default_charset', "UTF-8");
	
	$appointmentNo = mysqli_real_escape_string($conn,$_POST["appointmentNo"]);
	$isPayStatus = mysqli_real_escape_string($conn,$_POST["isPayStatus"]);
	
	$selectSql = "select count(appointment_no) countnNum from visit where appointment_no=".$appointmentNo;
	$result =  mysqli_query($conn, $selectSql);
	$row = mysqli_fetch_array($result);
	$count = $row["countnNum"];
	
	$data = "{\"data\":{";
	
	if( $count == 0 ){
		$data .= "\"status\":\"fail\",\"msg\":\"data error, this appointment not exist!!\"}}";
		echo $data;
		return;
	}
	
	$setPaySql = "update visit set isPay=".$isPayStatus." where appointment_no=".$appointmentNo;
	$result = mysqli_query($conn, $setPaySql);
	
	//echo $reuslt;
	if( $result ){
		$data .= "\"status\":\"success\",\"msg\":\"update ispay status success!!\"}}";
	}else{
		$data .= "\"status\":\"fail\",\"msg\":\"sql error!!".mysqli_error($conn)."\"}}";
	}
	
	echo $data;
	
	
?>